package renShiString;

import java.util.Locale;
import java.util.Scanner;

public class Test {
    public static void main1(String[] args) {
        //String类赋值的三种方式
        String str="hello";
        String str2=new String("world");
        char[] value={'a','b','c'};
        String str3=new String(value);

        System.out.println(str);
        System.out.println(str2);
        System.out.println(str3);
    }

    public static void main2(String[] args) {
        String s1=new String("hello");
        String s2=new String("hello");
        String s3=s1;
        //==比较的是地址
        System.out.println("============");
        System.out.println(s1==s2);//false
        System.out.println(s1==s3);//true
        System.out.println(s2==s3);//false
        System.out.println("============");
        //equals比较String存放的值
        System.out.println(s1.equals(s2));//true
        System.out.println(s1.equals(s3));//true
        System.out.println(s2.equals(s3));//true
    }

    public static void main3(String[] args) {
        String s1=new String("aeF");
        String s2=new String("aef");
        //比较字符串的大小
        //compareTo比较的是的是俩个字符串的ASC码
        //如果字符相同就继续比较，如果不同就比较差值
        System.out.println(s1.compareTo(s2));
        //1、跟据对应字符比较
        //2、对应字符 无法比较出来 谁大 谁小 此时 就看长度
        System.out.println(s1.compareToIgnoreCase(s2));
        //忽略大小写
    }

    public static void main4(String[] args) {
       String s="ababcabcd";
       /* //倒着往回的 第一个ab
        int index=s.lastIndexOf("abc",4);
        System.out.println(index);*/

        int index=s.indexOf('1');//默认是从0位置开始找
        System.out.println(index);//-1没找到

        index=s.indexOf('b',3);
        System.out.println(index);

        index=s.indexOf('1',3);//默认是从0开始找
        System.out.println(index);

        for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            System.out.println(ch);
        }

        char ch=s.charAt(5);
        System.out.println(ch);
        int[] array={1,2,3,4,5};
        System.out.println(array.length);
    }

    public static void main5(String[] args) {
        String s1=String.valueOf(1234);
        String s2=String.valueOf(12.34);
        String s3=String.valueOf(true);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);

        /*String s4=String.valueOf(new Student("gaobo",13));
        System.out.println(s4);*/

        int data1=Integer.parseInt("1234");
        double data2=Double.parseDouble("12.34");
        System.out.println(data1+1);
        System.out.println(data2);
    }

    public static void main6(String[] args) {
        String s="hello";
        String s2=s.toUpperCase();
        System.out.println(s2);

        String s3="Hel汉字lo9";
        System.out.println(s3.toLowerCase());
    }

    public static void main7(String[] args) {
        String s="hello";
        char[] array=s.toCharArray();
        for (int i = 0; i <array.length ; i++) {
            System.out.println(array[i]);
        }
        String s2=String.format("%d,%d,%d",2019,9,14);
        System.out.println(s2);
    }

    public static void main8(String[] args) {
        String s="ababcabcd";
        String tmp=s.replace('a','k');
        System.out.println(tmp);

        tmp=s.replace("ab","uuu");
        System.out.println(tmp);

        tmp=s.replaceFirst("ab","ooo");
        System.out.println(tmp);

        tmp=s.replaceAll("ab","ooo");
        System.out.println(tmp);
    }

    public static void main9(String[] args) {
        //"name=zhangsan&age=10"
        String s="name=zhangsan&&age=10";
        //返回值 是数组
        String[] strings=s.split("&");
        for (int i = 0; i < strings.length; i++) {
           /* strings[i]=name=zhangsan;
            strings[i]=age=zhangsan;*/
            System.out.println(strings[i]);
            String[] ss=strings[i].split("==");
            for (int j = 0; j < ss.length; j++) {
                System.out.println(ss[j]+"");
            }
            System.out.println();
        }
    }

    public static void main10(String[] args) {
        String s="192.168.0.1";
        String[] strings=s.split("\\.");//转义字符需要\\
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }
    }

    public static void main11(String[] args) {
        String s="ab\\cd\\ef";//\是转义字符
        System.out.println(s);

        String[] strings=s.split("\\\\");
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }
    }

    public static void main12(String[] args) {
        String s="name=zhangsan&age=10";
        //返回值 是数组
        String[] strings=s.split("=|&");
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }
    }

    public static void main13(String[] args) {
        String s="abcdef";
        String s2=s.substring(2,4);//[)
        System.out.println(s2);
    }

    public static void main14(String[] args) {
        String s="   abc d e f g  ";
        System.out.println(s);

        String s2=s.trim();//只会去除  左右俩边的空格
        System.out.println(s2);
    }

    public static void main15(String[] args) {
        String s="abcd";

        final char[] array={'a','b','c'};
        array[0]='g';//可以改变堆区的值

        //array=new char[10];
    }

    public static void main16(String[] args) {
        String s="hello";
        s+="world";//s=s+...
        System.out.println(s);
    }

    public static void main17(String[] args) {
        StringBuffer stringBuffer=new StringBuffer();
        stringBuffer.append("hello");
        stringBuffer.append("world");
        String ret = stringBuffer.toString();
        System.out.println(ret);
    }

    public static void main18(String[] args) {
        //string的+号拼接是最低效的
        long start =System.currentTimeMillis();//毫秒
        String s="";
        for (int i = 0; i < 10000; i++) {
            s+=i;
        }
        long end =System.currentTimeMillis();
        System.out.println(end - start);

        start=System.currentTimeMillis();
        StringBuffer sbf=new StringBuffer("");
        for (int i = 0; i < 10000; ++i) {
            sbf.append(i);
        }
        end=System.currentTimeMillis();
        System.out.println(end - start);

        start=System.currentTimeMillis();
        StringBuilder sbd=new StringBuilder();
        for (int i = 0; i < 10000; i++) {
            sbd.append(i);
        }
        end=System.currentTimeMillis();
        System.out.println(end-start);
    }

    public static void main19(String[] args) {
        StringBuilder stringBuilder=new StringBuilder("abcdef");
        stringBuilder.insert(3,"hahah");
        stringBuilder.reverse();
        System.out.println(stringBuilder);//
    }

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        String str=scan.nextLine();

        //1、字符串的分割   split()

      /*  String[] ss=str.split(" ");
        int len=ss[ss.length-1].length();

        System.out.println(len);*/

        //2、找到最后一个空格的下标，然后截取空格后的字符串，然后求长度 lastindexOf subString()
        int index=str.lastIndexOf(" ");
        int len=str.substring(index+1).length();
        System.out.println(len);
    }
}
